package com.ruoyi.irtu.controller;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.irtu.service.IIrtuDeviceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 设备Controller
 *
 * @author wb
 * @date 2023-03-13
 */
@RestController
@RequestMapping("/irtu/devices")
public class IrtuUpgradeController extends BaseController {

    /**
     * 设备升级接口
     */
    @ApiOperation("设备升级接口")
    @Anonymous
    @GetMapping(value = "/upgrade/{deviceImei}/param")
    public Data upgrade(@PathVariable("deviceImei") String deviceImei,
                              @RequestParam("product_name") String productName,
                              @RequestParam("param_ver") String paramVer) {
        logger.info("deviceImei: " + deviceImei);
        logger.info("productName: " + productName);
        logger.info("paramVer: " + paramVer);
        // 构造返回结果
//        Result result = new Result();
        Data data = new Data();
        data.setParamVer(paramVer);
        data.setProductName(productName);
//        result.setData(data);
//        result.setResult(false);
//        result.setMsg("请求成功");
        // 将JSON对象转换为字符串并打印
        logger.info(JSON.toJSONString(data));
        return data;
    }

    // 定义一个返回结果类
    public static class Result {
        private boolean result;
        private String msg;
        private Object data;

        // getter和setter方法
        public void setResult(boolean result)
        {
            this.result = result;
        }
        public boolean getResult()
        {
            return result;
        }
        public void setMsg(String msg)
        {
            this.msg = msg;
        }
        public String getMsg()
        {
            return msg;
        }
        public void setData(Object data)
        {
            this.data = data;
        }
        public Object getData()
        {
            return data;
        }
    }

    // 定义一个数据类
    public static class Data {
        @JsonProperty("param_ver")
        private String paramVer;

        @JsonProperty("product_name")
        private String productName;

        // getter和setter方法
        public void setParamVer(String paramVer)
        {
            this.paramVer = paramVer;
        }
        public String getParamVer()
        {
            return paramVer;
        }
        public void setProductName(String productName)
        {
            this.productName = productName;
        }
        public String getProductName()
        {
            return productName;
        }
    }
}
